<template>
  <div class="homeContainer">
    <ChinaMap />
    <div class="homeCenterRightBox">
      <div class="tongjiBg">
        <p>总览统计</p>
        <div class="timeLeft">
          <div class="top">
            <i class="leftArraw"></i>
            <span class="floatTimeTitle">起始时间</span>
            <i class="rightArraw"></i>
            <span class="floatUtcTime">{{ curUtcTime }}</span>
            <span class="floatUtcTime floatUtcTime1">00:00:00</span>
          </div>
          <div class="bottom">
            <i class="leftArraw"></i>
            <span class="floatTimeTitle">结束时间</span>
            <i class="rightArraw"></i>
            <span class="floatUtcTime">{{ curUtc3DayTime }}</span>
            <span class="floatUtcTime floatUtcTime1">00:00:00</span>
          </div>
        </div>
        <div class="totalRight">
          <div class="kindTotal">
            <i class="icon icon1"></i>
            <div class="kindRightText">
              <span class="span1">机场总数</span>
              <span class="span2">{{ airportCounts }}</span>
            </div>
          </div>
          <div class="kindTotal">
            <i class="icon icon2"></i>
            <div class="kindRightText">
              <span class="span1">区域总数</span>
              <span class="span2">{{ areaCounts }}</span>
            </div>
          </div>
          <div class="kindTotal">
            <i class="icon icon3"></i>
            <div class="kindRightText">
              <span class="span1">航路总数</span>
              <span class="span2">{{ routeCounts }}</span>
            </div>
          </div>
          <div class="kindTotal">
            <i class="icon icon4"></i>
            <div class="kindRightText">
              <span class="span1">航线总数</span>
              <span class="span2">-</span>
            </div>
          </div>
        </div>
      </div>
      <div class="baowenBg">
        <p>报文编号</p>
        <div style="width: 200px; float: right; margin-top: 5px">
          <div
            v-for="(item, index) in baowenTabList"
            :key="index"
            @click="handlebaowenClick(index)"
            :class="[
              'baowenTab',
              currbaowenIndex === index ? 'currbaowenIndex' : '',
            ]"
          >
            {{ item.name }}
          </div>
        </div>
        <!-- table 展示 -->
        <div class="tableScrollContainer">
          <el-table
            v-show="currbaowenIndex == 0"
            :data="tableData01"
            stripe
            style="padding: 16px 8px 0 8px"
            :row-class-name="tableRowClassName"
            :header-cell-style="headerCellStyle"
            :cell-style="cellStyle"
          >
            <el-table-column prop="id" label="NANU报文编号" width="110" />
            <el-table-column prop="prnCode" label="PRN" width="98" />
            <el-table-column prop="startTime" label="开始时间" width="130" />
            <el-table-column prop="endTime" label="结束时间" width="130" />
          </el-table>
          <el-table
            v-show="currbaowenIndex == 1"
            :data="tableData02"
            stripe
            style="padding: 16px 8px 0 8px"
            :row-class-name="tableRowClassName"
            :header-cell-style="headerCellStyle"
            :cell-style="cellStyle"
          >
            <el-table-column prop="date" label="NOTAM报文编号" width="110" />
            <el-table-column prop="aaa" label="PRN" width="90" />
            <el-table-column prop="name" label="开始时间" width="130" />
            <el-table-column prop="address" label="结束时间" width="130" />
          </el-table>
        </div>
      </div>
    </div>
    <!-- <div class="centerTotals">333</div> -->
    <div class="homeFooter">
      <div class="homeFooterTop">
        <div class="homeFooterTopLeft">
          <p>BDS</p>
          <div class="homeFotterKind">
            <div class="kindTotal">
              <i class="icon icon1"></i>
              <div class="kindRightText">
                <span class="span1">BDS历书周</span>
                <span class="span2">{{ BDS.almanacWeek }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon2"></i>
              <div class="kindRightText">
                <span class="span1">BDS周内秒</span>
                <span class="span2">{{ BDS.secondsOfWeek }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon3"></i>
              <div class="kindRightText">
                <span class="span1">BDS不可用卫星</span>
                <span class="span2">{{ BDS.unhealthyCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon4"></i>
              <div class="kindRightText">
                <span class="span1">BDS卫星总数</span>
                <span class="span2">{{ BDS.totalCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon5"></i>
              <div class="kindRightText">
                <span class="span1">BDS可用卫星</span>
                <span class="span2">{{ BDS.healthyCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon6"></i>
              <div class="kindRightText">
                <span class="span1">不可用卫星编号</span>
                <span class="span2" style="color: #00afff">{{
                  Array.isArray(BDS.unhealthyPrnCodes) &&
                  BDS.unhealthyPrnCodes.length > 0
                    ? BDS.unhealthyPrnCodes
                    : "-"
                }}</span>
              </div>
            </div>
          </div>
        </div>
        <div class="homeFooterTopRight">
          <p>GPS</p>
          <div class="homeFotterKind">
            <div class="kindTotal">
              <i class="icon icon1"></i>
              <div class="kindRightText">
                <span class="span1">GPS历书周</span>
                <span class="span2">{{ GPS.almanacWeek }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon2"></i>
              <div class="kindRightText">
                <span class="span1">GPS周内秒</span>
                <span class="span2">{{ GPS.secondsOfWeek }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon3"></i>
              <div class="kindRightText">
                <span class="span1">GPS不可用卫星</span>
                <span class="span2">{{ GPS.unhealthyCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon4"></i>
              <div class="kindRightText">
                <span class="span1">GPS卫星总数</span>
                <span class="span2">{{ GPS.totalCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon5"></i>
              <div class="kindRightText">
                <span class="span1">GPS可用卫星</span>
                <span class="span2">{{ GPS.healthyCount }}</span>
              </div>
            </div>
            <div class="kindTotal">
              <i class="icon icon6"></i>
              <div class="kindRightText">
                <span class="span1">不可用卫星编号</span>
                <span class="span2" style="color: #00afff">{{
                  Array.isArray(GPS.unhealthyPrnCodes) &&
                  GPS.unhealthyPrnCodes.length > 0
                    ? GPS.unhealthyPrnCodes
                    : "-"
                }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="footerTime">
        <p>当前时间(UTC)：{{ utcTime }}</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, defineAsyncComponent, onMounted } from "vue";
import { useTime } from "@/utils/tools/useTime";
import localStorageUtil from "@/utils/tools/localStorageUtil";
import {
  satellitesDataApi,
  getAreaCountApi,
  getAirportCountApi,
  getRouteCountApi,
  getSatellitesNanusApi,
} from "@/api/home";

const BDS = reactive({});
const GPS = reactive({});
const routeCounts = ref("");
const areaCounts = ref("");
const airportCounts = ref("");
// const gps = ref("");
const curUtcTime = ref("");
const curUtc3DayTime = ref("");
const tableData01 = ref([]);
const tableData02 = ref([]);

const { utcTime, formatTimeHasDay, getThreeDaysLaterFormatted } = useTime();
const date = new Date();
curUtcTime.value = formatTimeHasDay(date); //起始时间
curUtc3DayTime.value = getThreeDaysLaterFormatted(); //结束时间
const currbaowenIndex = ref(0);
const baowenTabList = ref([{ name: "NANU" }, { name: "NOTAM" }]);
localStorageUtil.set("startTime", curUtcTime.value + " 00:00:00");
localStorageUtil.set("endTime", curUtc3DayTime.value + " 00:00:00");

tableData02.value = [
  {
    date: "20250012025001",
    aaa: 111111,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 111111,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 2025001,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 111111,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 111111,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 2025001,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
  {
    date: "20250012025001",
    aaa: 2025001,
    name: "2025/08/08  9:30:00",
    address: "2025/08/08  9:30:00",
  },
];

// 表格样式相关方法
const tableRowClassName = ({ rowIndex }) => {
  // 斑马线效果
  return rowIndex % 2 === 0 ? "table-row-even" : "table-row-odd";
};

const headerCellStyle = () => {
  // 表头样式background: rgba(0, 175, 255, 0.20);
  return {
    height: "32px",
    "background-color": "rgba(0, 175, 255, 0.20)",
  };
};

const cellStyle = () => {
  // 单元格基础样式display: flex;
  return {
    "font-size": "12px",
    color: "#fff",
    height: "32px",
    "flex-shrink": 0,
    "border-bottom": "1px solid rgba(31, 198, 255, 0.15)",
  };
};

// 用异步组件包装ChinaMap，实现延迟加载（不阻塞HOME组件渲染）
const ChinaMap = defineAsyncComponent({
  // 动态导入：路由切换到HOME时，不会立即加载ChinaMap的代码
  loader: () => import("@/views/home/components/ChinaMap.vue"),
  // 加载超时/失败时显示的组件（可选）
  errorComponent: { template: "<div>地图加载失败，请刷新重试</div>" },
  // 加载超时时间（毫秒）
  timeout: 5000,
});

const handlebaowenClick = (index) => {
  currbaowenIndex.value = index;
};
onMounted(() => {
  const satellitesNanus = async () => {
    const { code, data } = await getSatellitesNanusApi();
    if (code === 200) {
      tableData01.value = data;
    }
  };
  satellitesNanus();
  const satellitesData = async () => {
    const { code, data } = await satellitesDataApi();
    if (code === 200) {
      BDS.almanacWeek = data.bds.almanacWeek;
      BDS.secondsOfWeek = data.bds.secondsOfWeek;
      BDS.unhealthyCount = data.bds.unhealthyCount;
      BDS.totalCount = data.bds.totalCount;
      BDS.healthyCount = data.bds.healthyCount;
      BDS.unhealthyPrnCodes = data.bds.unhealthyPrnCodes;
      GPS.almanacWeek = data.gps.almanacWeek;
      GPS.secondsOfWeek = data.gps.secondsOfWeek;
      GPS.unhealthyCount = data.gps.unhealthyCount;
      GPS.totalCount = data.gps.totalCount;
      GPS.healthyCount = data.gps.healthyCount;
      GPS.unhealthyPrnCodes = data.gps.unhealthyPrnCodes;
    }
  };
  satellitesData();
  const areaCount = async () => {
    const { code, data } = await getAreaCountApi();
    if (code === 200) {
      areaCounts.value = data || "-";
    }
  };
  areaCount();
  const airportCount = async () => {
    const { code, data } = await getAirportCountApi();
    if (code === 200) {
      airportCounts.value = data || "-";
    }
  };
  airportCount();
  const routeCount = async () => {
    const { code, data } = await getRouteCountApi();
    if (code === 200) {
      routeCounts.value = data || "-";
    }
  };
  routeCount();
});
</script>

<style scoped lang="scss">
.homeContainer {
  height: calc(100vh - 66px);
  /* width: 1440px; margin: 0 auto; */
  .homeFooter {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 264px;
    .homeFooterTop {
      height: 228px;
      overflow: hidden;
      .homeFooterTopLeft {
        margin-top: 2px;
        margin-left: 24px;
        float: left;
        width: 684px;
        height: 224px;
        background-image: url("../../assets/images/home/GPSbg.png");
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
        p {
          float: left;
          text-align: left;
          margin-left: 16px;
          color: #fff;
          font-size: 20px;
          font-weight: 700;
          line-height: 44px;
        }
        .homeFotterKind {
          position: relative;
          width: 684px;
          clear: both;
          overflow: hidden;
          padding-top: 10px;
          .kindTotal {
            float: left;
            width: 180px;
            height: 58px;
            margin-top: 17px;
            margin-left: 22px;
            .icon {
              float: left;
              width: 48px;
              height: 54px;
              background-repeat: no-repeat;
              background-size: contain;
              background-position: center;
            }
            .icon1 {
              background-image: url("../../assets/images/home/liszhou.png");
            }
            .icon2 {
              background-image: url("../../assets/images/home/zneimiao.png");
            }
            .icon3 {
              background-image: url("../../assets/images/home/nocanws.png");
            }
            .icon4 {
              background-image: url("../../assets/images/home/wszhoushu.png");
            }
            .icon5 {
              background-image: url("../../assets/images/home/kecanws.png");
            }
            .icon6 {
              background-image: url("../../assets/images/home/bucancode.png");
            }
            .kindRightText {
              position: relative;
              float: left;
              margin-left: 12px;
              .span1 {
                color: #c5d6e6;
                font-size: 14px;
                font-weight: 400;
                line-height: 22px;
                display: block;
              }
              .span2 {
                display: block;
                color: #fff;
                font-size: 20px;
                font-style: normal;
                font-weight: 700;
                line-height: 28px;
                text-align: left;
              }
            }
          }
        }
      }
      .homeFooterTopRight {
        margin-top: 2px;
        margin-right: 24px;
        float: right;
        width: 684px;
        height: 224px;
        background-image: url("../../assets/images/home/GPSbg.png");
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
        p {
          float: left;
          text-align: left;
          margin-left: 16px;
          color: #fff;
          font-size: 20px;
          font-weight: 700;
          line-height: 44px;
        }
        .homeFotterKind {
          position: relative;
          width: 684px;
          clear: both;
          overflow: hidden;
          padding-top: 10px;
          .kindTotal {
            float: left;
            width: 180px;
            height: 58px;
            margin-top: 17px;
            margin-left: 22px;
            .icon {
              float: left;
              width: 48px;
              height: 54px;
              background-repeat: no-repeat;
              background-size: contain;
              background-position: center;
            }
            .icon1 {
              background-image: url("../../assets/images/home/liszhou.png");
            }
            .icon2 {
              background-image: url("../../assets/images/home/zneimiao.png");
            }
            .icon3 {
              background-image: url("../../assets/images/home/nocanws.png");
            }
            .icon4 {
              background-image: url("../../assets/images/home/wszhoushu.png");
            }
            .icon5 {
              background-image: url("../../assets/images/home/kecanws.png");
            }
            .icon6 {
              background-image: url("../../assets/images/home/bucancode.png");
            }
            .kindRightText {
              position: relative;
              float: left;
              margin-left: 12px;
              .span1 {
                color: #c5d6e6;
                font-size: 14px;
                font-weight: 400;
                line-height: 22px;
                display: block;
              }
              .span2 {
                display: block;
                color: #fff;
                font-size: 20px;
                font-style: normal;
                font-weight: 700;
                line-height: 28px;
                text-align: left;
              }
            }
          }
        }
      }
    }
  }
}
.homeCenterRightBox {
  float: right;
  .tongjiBg {
    margin-top: 28px;
    margin-right: 24px;
    width: 484px;
    height: 240px;
    background-image: url("../../assets/images/home/zlTotal.png");
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    p {
      text-align: left;
      margin-left: 16px;
      color: #fff;
      font-size: 20px;
      font-weight: 700;
      line-height: 44px;
    }
    .timeLeft {
      float: left;
      width: 100px;
      margin-top: 24px;
      margin-left: 30px;
      .top {
        position: relative;
      }
      .bottom {
        position: relative;
        margin-top: 20px;
      }
      .leftArraw {
        margin-top: 2px;
        float: left;
        width: 8px;
        height: 16px;
        background-image: url("../../assets/images/home/arrowLeft.png");
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
      }
      .rightArraw {
        margin-top: 2px;
        float: right;
        width: 8px;
        height: 16px;
        background-image: url("../../assets/images/home/arrowRight.png");
        background-repeat: no-repeat;
        background-size: contain;
        background-position: center;
      }
      .floatTimeTitle {
        color: #b4c0cc;
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        line-height: 22px;
      }
      .floatUtcTime {
        color: #fff;
        text-align: center;
        font-size: 14px;
        font-weight: 700;
        line-height: 22px;
      }
      .floatUtcTime1 {
        display: block;
      }
    }
    .totalRight {
      float: right;
      width: 320px;
      .kindTotal {
        float: left;
        width: 132px;
        height: 58px;
        margin-top: 30px;
        margin-left: 10px;
        .icon {
          float: left;
          width: 48px;
          height: 54px;
          background-repeat: no-repeat;
          background-size: contain;
          background-position: center;
        }
        .icon1 {
          background-image: url("../../assets/images/home/airTotal.png");
        }
        .icon2 {
          background-image: url("../../assets/images/home/areaTotal.png");
        }
        .icon3 {
          background-image: url("../../assets/images/home/routeTotal.png");
        }
        .icon4 {
          background-image: url("../../assets/images/home/lineTotal.png");
        }
        .kindRightText {
          position: relative;
          float: left;
          margin-left: 12px;
          .span1 {
            color: #c5d6e6;
            font-size: 14px;
            font-weight: 400;
            line-height: 22px;
            display: block;
          }
          .span2 {
            display: block;
            color: #fff;
            font-size: 20px;
            font-style: normal;
            font-weight: 700;
            line-height: 28px;
            text-align: left;
          }
        }
      }
    }
  }
  .baowenBg {
    margin-top: 28px;
    margin-right: 24px;
    width: 484px;
    height: 274px;
    background-image: url("../../assets/images/home/baowenbg.png");
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    p {
      float: left;
      text-align: left;
      margin-left: 16px;
      color: #fff;
      font-size: 20px;
      font-weight: 700;
      line-height: 44px;
    }
    .baowenTab {
      cursor: pointer;
      margin-left: 8px;
      float: left;
      display: flex;
      width: 88px;
      height: 32px;
      padding: 4px 12px;
      justify-content: center;
      align-items: center;
      gap: 10px;
      flex-shrink: 0;
      background: rgba(0, 175, 255, 0.1);
      color: #98a7af;
      font-size: 16px;
      font-weight: 400;
    }
    .currbaowenIndex {
      color: #fff;
      font-size: 16px;
      font-weight: 700;
      display: flex;
      width: 88px;
      padding: 4px 12px;
      justify-content: center;
      align-items: center;
      gap: 10px;
      border-bottom: 2px solid #1fc6ff;
      background: linear-gradient(
        0deg,
        rgba(31, 198, 255, 0.32) 0%,
        rgba(31, 198, 255, 0) 100%
      );
    }
  }
}
.footerTime {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 28px;
  background-color: #050d24;
  p {
    color: #fff;
    text-align: right;
    font-size: 12px;
    line-height: 28px;
    padding-right: 16px;
  }
}
.baowenBg .tableScrollContainer {
  height: 224px;
  clear: both;
  overflow-y: auto;
  overflow-x: auto;
}

.baowenBg .tableScrollContainer::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.baowenBg .tableScrollContainer::-webkit-scrollbar-thumb {
  background-color: rgba(31, 198, 255, 0.4);
  border-radius: 2px;
}
.baowenBg .tableScrollContainer::-webkit-scrollbar-track {
  background-color: rgba(10, 30, 60, 0.3);
}
/* 表格容器背景透明 */
:deep(.el-table) {
  background-color: transparent !important;
  border: none;
}
:deep(.el-table__body tr) {
  background-color: transparent !important;
}

:deep(.el-table__header tr) {
  color: #c5d6e6;
  font-size: 12px;
  font-weight: 400;
  line-height: 20px;
  background-color: transparent !important;
}
/* 斑马线样式：偶数行 */
:deep(.table-row-even) {
  background-color: rgba(0, 59, 122, 0.2) !important;
}

/* 斑马线样式：奇数行 */
:deep(.table-row-odd) {
  background-color: transparent !important;
}

/* 表格行hover效果 */
:deep(.el-table__row:hover > td) {
  background-color: rgba(0, 59, 122, 0.2) !important;
}

/* 去掉表格默认边框线 */
:deep(.el-table__inner-wrapper::before) {
  background-color: transparent !important;
}
:deep(.el-table__cell) {
  border-bottom: none !important;
}
/* 关键：修改斑马线行的单元格背景色 */
:deep(
    .el-table--striped
      .el-table__body
      tr.el-table__row--striped
      td.el-table__cell
  ) {
  padding: 0;
  background-color: rgba(0, 59, 122, 0.2) !important;
}
:deep(.el-table .cell) {
  padding-right: 0 !important;
}
</style>
